package com.zsgl.dao;

import java.util.List;
import java.io.Serializable;
import com.zsgl.domain.Tour;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;

public class TourDAOImpl implements TourDAO {
	
	private HibernateTemplate template;
	
	@Autowired
	public TourDAOImpl(HibernateTemplate template) {
		this.template = template;
	}
	
	public HibernateTemplate getTemplate() {
		return template;
	}
	
	public Tour create() {
		return new Tour();
	}
	
	public Tour save(Tour obj) {
		template.save(obj);
		return obj;
	}

	public void delete(Tour obj) {
		template.delete(obj);
	}
	
	public void update(Tour obj) {
		template.update(obj);
	}
	
	public Tour find(Serializable id) {
		return template.get(Tour.class, id);
	}
	
	@SuppressWarnings("unchecked")
	public List<Tour> findAll() {
		return (List<Tour>)template.find("from Tour");
	}
	
	@SuppressWarnings("unchecked")
	public List<Tour> find(int firstResult, int maxResult) {
		return template.findByCriteria(DetachedCriteria.forClass(Tour.class), firstResult, maxResult);
	}
	
	public long count() {
		return (Long)template.find("select count(o) from Tour o").listIterator().next();
	}
}